package com.imooc.sell.VO.pan;

import com.imooc.sell.dataobject.Remark;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 传给前端的数据封装类
 */
@SuppressWarnings("all")
public class RemarkRemarkMap {
    public int mCode;

    public String msg;


    private ArrayList<HashMap<String, RemarkVO>> remarkremarkmap = new ArrayList<>();

    public RemarkRemarkMap() {
        this.mCode = 0;
        this.msg = "失败";
        this.remarkremarkmap = null;
    }

    public RemarkRemarkMap(int mCode, String msg, List<Remark> remarkList) {
        ArrayList<ArrayList<RemarkVO>> remarkremark = new ArrayList<>();
        this.mCode = mCode;
        this.msg = msg;
        int i = 1;
        for (Remark remark : remarkList) {
            if (i == 1) {
                ArrayList<RemarkVO> remarks = new ArrayList<>();
                remarks.add(new RemarkVO(remark));
                remarkremark.add(remarks);
            } else {
                boolean isadd = false;
                for (List<RemarkVO> rr : remarkremark) {
                    if (remark.getOrderId().equals(rr.get(0).getOrderId())) {
                        rr.add(new RemarkVO(remark));
                        isadd = true;
                    }
                }
                if (!isadd) {
                    ArrayList<RemarkVO> remarks = new ArrayList<>();
                    remarks.add(new RemarkVO(remark));
                    remarkremark.add(remarks);
                }
            }
            i++;
        }

        for (ArrayList<RemarkVO> ar : remarkremark) {
            HashMap map = new HashMap();
            map.put("business", "");
            map.put("user", "");
            for (RemarkVO r : ar) {
                if (r.getNickName().equals("") && r.getHeadImg().equals("")) {
                    map.put("business", r);
                } else {
                    map.put("user", r);
                }
            }
            remarkremarkmap.add(map);
        }
    }

    public int getmCode() {
        return mCode;
    }

    public void setmCode(int mCode) {
        this.mCode = mCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ArrayList<HashMap<String, RemarkVO>> getRemarkremarkmap() {
        return remarkremarkmap;
    }

    public void setRemarkremarkmap(ArrayList<HashMap<String, RemarkVO>> remarkremarkmap) {
        this.remarkremarkmap = remarkremarkmap;
    }

    @Override
    public String toString() {
        String str = "";
        for (HashMap mp : remarkremarkmap) {
            for (Object key : mp.keySet()) {
                System.out.println("Key: " + key + " Value: " + mp.get(key));
                str += mp.get(key).toString();
            }
            /*str+= mp.get("bussiss").toString();
            str+= mp.get("user").toString();*/
        }
        return "RemarkRemark{" +
                "mCode=" + mCode +
                ", msg='" + msg + '\'' +
                ", remarkremarkmap=" + str +
                '}';
    }
}
